package com.zhuiyun.project.api.plan.fitnessPurpose.service.impl;

import com.zhuiyun.project.api.plan.fitnessPurpose.service.FitnessPurposeService;
import com.zhuiyun.project.api.plan.fitnessPurpose.entity.FitnessPurpose;
import com.zhuiyun.project.api.plan.fitnessPurpose.mapper.FitnessPurposeMapper;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.errorCode.EmErrorCode;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import com.zhuiyun.project.utils.pageUtil.PageResult;
import com.zhuiyun.project.utils.validator.ValidatorUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName FitnessActionServiceImpl
 * @Description TODO
 * @Author ys
 * @Date 2023/11/2 9:01
 **/
@Service
public class FitnessPurposeServiceImpl implements FitnessPurposeService {
    @Resource
    private FitnessPurposeMapper fitnessPurposeMapper;
    /**
     * @Author 杨珅
     * @Description todo 健身目的查询
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public PageResult selectAll(PageRequest pageRequest, String fitnessPurposeName,String venueUniqueIdentifier) {
        MybatisPageHelper.startPage(pageRequest);// 使用MybatisPageHelper实现分页功能，设置分页信息
        List<FitnessPurpose> PurposeList = fitnessPurposeMapper.selectAll(pageRequest, fitnessPurposeName, venueUniqueIdentifier);// 调用ArticleReviewMapper的getArticle方法查询文章列表\
        return MybatisPageHelper.getPageResult(PurposeList);
    }
    
    /**
    * @Author 摸鱼飞弹
    * @Description TODO 健身目的查询
    * @Date 2024/3/4 15:00
    * @Return 
    * @param null
    */
    @Override
    public CommonResult selectAll(String fitnessPurposeName, String venueUniqueIdentifier) {
        return CommonResult.ok(fitnessPurposeMapper.selectAll(fitnessPurposeName,venueUniqueIdentifier));
    }

    /**
     * @Author 杨珅
     * @Description todo 健身目的查询
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult queryAll(String venueUniqueIdentifier) {
        return CommonResult.ok(fitnessPurposeMapper.queryAll(venueUniqueIdentifier));
    }
    /**
     * @Author 杨珅
     * @Description todo 健身目的新增
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult insertFitnessPurpose(FitnessPurpose fitnessPurpose)throws CommonException {
        if (ValidatorUtil.ValidationObject(fitnessPurpose)){
            fitnessPurpose.setCreateTime(new Date());
            fitnessPurpose.setUpdateTime(new Date());
            int i = fitnessPurposeMapper.insertFitnessPurpose(fitnessPurpose);
            if (i >= 1) {
                return CommonResult.ok(EmErrorCode.SAVE_OK);
            }else {
                return CommonResult.ok(EmErrorCode.SAVE_ERROR);
            }
        } else{
            return CommonResult.ok(EmErrorCode.SAVE_ERROR);
        }
    }
    /**
     * @Author 杨珅
     * @Description todo 健身目的新增
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult updateFitnessPurpose(FitnessPurpose fitnessPurpose)throws  CommonException {
        if (ValidatorUtil.ValidationObject(fitnessPurpose)){
            fitnessPurpose.setCreateTime(new Date());
            fitnessPurpose.setUpdateTime(new Date());
            int i = fitnessPurposeMapper.updateFitnessPurpose(fitnessPurpose);
            if (i >= 1) {
                return CommonResult.ok(EmErrorCode.UPDATE_OK);
            }else {
                return CommonResult.ok(EmErrorCode.UPDATE_ERROR);
            }
        } else{
            return CommonResult.ok(EmErrorCode.UPDATE_ERROR);
        }
    }
    /**
     * @Author 杨珅
     * @Description todo 健身目的删除
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult deleteFitnessPurpose(FitnessPurpose fitnessPurpose) {
        return CommonResult.ok(fitnessPurposeMapper.deleteFitnessPurpose(fitnessPurpose));
    }
}
